package com.garlicts.framework.crawler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(CrawlerTemplate.class)
@EnableConfigurationProperties(CrawlerTemplateProperties.class)
public class CrawlerTemplateAutoConfigure {

	@Autowired
	private CrawlerTemplateProperties crawlerTemplateProperties;
	
	@Bean
	@ConditionalOnMissingBean
	@ConditionalOnProperty(prefix="com.garlicts.framework.crawler", value="enabled", havingValue="true")
	CrawlerTemplate crawlerTemplate() {
		return new CrawlerTemplate(crawlerTemplateProperties.getCrawlerNumber());
	}
	
}
